package Year22_Month06.day18;

public class 合并二叉树_方法二 {
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        return rebuildTree(root1,root2);
    }

    public TreeNode rebuildTree(TreeNode node1,TreeNode node2){
        if(node1 == null) return node2;
        if(node2 == null) return node1;
        node1.val += node2.val;
        node1.left = rebuildTree(node1.left,node2.left);
        node1.right = rebuildTree(node1.right,node2.right);
        return node1;
    }
}
